package Algorithm.AlgorithmBook.ChapterOne;

/**
 * 二维数组的转置
 */
public class Case1_1_13 {

    // 打印整个二维数组
    public static void print(int[][] a){

        int count = 0;
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[0].length; j++) {
                System.out.print(a[i][j]+"\t");
                count++;
            }
            if (count % a[0].length == 0) System.out.println();
        }
    }


    // 转置行列式
    public static int[][]  transpose(int[][] test){
        // 列
        int column = test.length;
        // 行
        int row = test[0].length;
        // 行转列，列换行
        int[][] b = new int[row][column];
        for (int i = 0; i < column; i++) {
            for (int j = 0; j < row; j++) {
                b[j][i] = test[i][j];
            }
        }

        return b;
    }


    public static void main(String[] args) {

        int[][] a = {{1,2,3,4}, {3,4,5,6}, {4,5,6,7}};

        print(a);
        System.out.println("==================");
        print(transpose(a));

    }

}
